//
//  HallViewController.m
//  彩票项目
//
//  Created by 伍银荣 on 2021/7/20.
//  Copyright © 2021 com.WYR. All rights reserved.
//

#import "HallViewController.h"

@interface HallViewController ()
@property (nonatomic, weak) UIView *coverViwe;
@property (nonatomic, weak) UIImageView *imgView;

@end

@implementation HallViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    self.title = @"购彩大厅";
//
//    self.view.backgroundColor = [UIColor blueColor];
    UIButton *btn = [[UIButton alloc]init];
    [btn setTitle:@"活动" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
    [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, -5)];
    btn.titleLabel.font = kFont(15);
    [btn setImage:[UIImage imageNamed:@"event"] forState:UIControlStateNormal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
    
    [btn addTarget:self action:@selector(actionBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    
    
}

- (void)actionBtnClick {
    //创建遮罩view
    UIView *coverView = [[UIView alloc]initWithFrame:kScreenSize];
    coverView.backgroundColor = [UIColor blackColor];
    coverView.alpha = 0.5;
    //使用最外层的view或者window添加就可以是导航栏和下面的标签栏都有遮罩
    [self.tabBarController.view addSubview:coverView];
    self.coverViwe = coverView;
    //创建imgView
    UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 250, 350)];
    //手动创建的按钮默认是没有开启与用户交互的
    imgView.userInteractionEnabled = YES;
    imgView.center = self.view.center;
    imgView.image = [UIImage imageNamed:@"zhaoyazhi"];
    //如果父控件是透明的,那么子控件也是透明的,所以这里将imgView添加到tabBarController而不是coverView上
    [self.tabBarController.view addSubview:imgView];
    self.imgView = imgView;
    //创建按钮
    UIImage *cancelImage = [UIImage imageNamed:@"quxiao"];
    UIButton *cancelBtn = [[UIButton alloc]initWithFrame:CGRectMake(imgView.frame.size.width - cancelImage.size.width, 0, 0, 0)];
    [cancelBtn setImage:cancelImage forState:UIControlStateNormal];
    [cancelBtn sizeToFit];
    [imgView addSubview:cancelBtn];
    [cancelBtn addTarget:self action:@selector(cancelBtnClick) forControlEvents:UIControlEventTouchUpInside];
}

- (void)cancelBtnClick {
    [UIView animateWithDuration:0.25 animations:^{
        [self.coverViwe removeFromSuperview];
        [self.imgView removeFromSuperview];
    }];
}

@end
